package com.lemon.smartsafety.http.service;

import android.content.Context;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.EventTag;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.entity.safe.contract.AgencyInfoVo;
import com.lemon.smartsafety.entity.safe.contract.KeepContractVo;
import com.lemon.smartsafety.http.UrlInfo;
import com.lemon.smartsafety.http.callback.HandlerCallback;
import com.lemon.smartsafety.utils.common.StringUtils;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.List;


/**
 * Created by Cooliean on 16/1/19.
 * 维保合同 相关 网络请求服务
 */
public class KeepContactServices extends BaseHttpServices {


    private static final String TAG = "KeepContactServices";


    private KeepContactServices(Context context) {
        super(context);
    }

    public static KeepContactServices init() {
        return new KeepContactServices(IApplication.context());
    }


    /**
     * 获取维保合同列表
     *
     * @return
     */
    public KeepContactServices getKeepContractList(String companyCode, String key_word,String typeId) {
        LemonRequestParams params = new LemonRequestParams();
        params.put("company_code", StringUtils.nullValue(companyCode));
        params.put("type_id", StringUtils.nullValue(typeId));
        if (null != key_word) {
            params.put("key_word", StringUtils.nullValue(key_word));
        }
        HandlerCallback<List<KeepContractVo>> callback = new HandlerCallback<List<KeepContractVo>>(EventTag.TAG_SAFE_KEEP_CONTRACT) {
        };
        callback.setOther(RefreshType.REFRESH);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.URL_SAFE_DATA_KEEP_CONTRACT);
        OkHttpUtils.post().url(serverUrl).tag(callback.getTag()).params(params).build().execute(callback);
        return this;
    }


    /**
     * 获取维保单位
     *
     * @return
     */
    public KeepContactServices getKeepUnitList(String key_word,String typeId) {
        LemonRequestParams params = new LemonRequestParams();
        if (null != key_word) {
            params.put("key_word", StringUtils.nullValue(key_word));
        }
        params.put("type_id", StringUtils.nullValue(typeId));
        HandlerCallback<List<AgencyInfoVo>> callback = new HandlerCallback<List<AgencyInfoVo>>(EventTag.TAG_SAFE_KEEP_CONTRACT_LIST) {
        };
        callback.setOther(RefreshType.REFRESH);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.URL_SAFE_DATA_KEEP_CONTRACT_UNIT_LIST);
        OkHttpUtils.post().url(serverUrl).tag(callback.getTag()).params(params).build().execute(callback);
        return this;
    }



    /**
     * 保存维保合同
     *
     * @return
     */
    public KeepContactServices saveKeepContractInfoAction(LemonRequestParams params, boolean isEdit) {
        HandlerCallback<String> callback = new HandlerCallback<String>(EventTag.TAG_SAFE_KEEP_CONTRACT_SAVE_ACTION) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(isEdit ? UrlInfo.URL_SAFE_DATA_KEEP_CONTRACT_EDIT_ACTION : UrlInfo.URL_SAFE_DATA_KEEP_CONTRACT_NEW_ACTION);
        OkHttpUtils.post().url(serverUrl).tag(callback.getTag()).params(params).build().execute(callback);
        return this;
    }


}
